how generators work